package bb.lanxing.util.text;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Parcel;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.view.View;

public class NoLineURLSpan extends ClickableSpan {
    private int color;
    private final String mURL;

    public int describeContents() {
        return 0;
    }

    public NoLineURLSpan(String url, int color) {
        this.mURL = url;
        this.color = color;
    }

    public NoLineURLSpan(Parcel src) {
        this.mURL = src.readString();
        this.color = src.readInt();
    }

    @Override
    public void updateDrawState(TextPaint ds) {
        ds.setColor(this.color);
        ds.setUnderlineText(false);
    }

    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.mURL);
        dest.writeInt(this.color);
    }

    public String getURL() {
        return this.mURL;
    }

    @Override
    public void onClick(View widget) {
        Uri parse = Uri.parse(getURL());
        Context context = widget.getContext();
        Intent intent = new Intent("android.intent.action.VIEW", parse);
        intent.putExtra("com.android.browser.application_id", context.getPackageName());
        context.startActivity(intent);
    }
}
